****************************************************************************************************************
**																											  **
** This do file is part of the replication material for the following article: 								  **
**  "Voter mobilization in the echo chamber: Broadbandinternet and the rise of populism in Europe" 	          **
** 		Authors: Max Schaub, Davide Morisi			    													  **
** 		Journal: European Journal of Political Research														  **
**																											  **
** This file replicates the following  step of the analysis: 												  **
**																											  **
**		ANALYSIS DATA GERMANY - PAPER AND APPENDIX								    						  **
**		Note: The analyses below have to be conducted in the GESIS Secure Data Centre in Cologne. 		      **																											  **
**            The access procedure is explained at                                                            **
**            https://www.gesis.org/en/services/data-analysis/more-data-to-analyze/secure-data-center-sdc.    **
**                                                                                                            **
****************************************************************************************************************

*Set working directory
cd "..."

ssc install fre

* Load data
use MV_SA_BW_RP_SH_combined_incl_plz.dta, clear

* Set control variables
local cntrls_de_individual age10 sex i.edu_cat3_rev employed
local cntrls_de age10 sex i.edu_cat3_rev employed popdens021 slope1 unempl01 over65_01 degrees_univ08 i.bik i.bl 

** Set sample
ivregress 2sls voteintent_afd `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)
drop sample
gen sample = e(sample) 
drop if sample!=1


//// Main models

*** Simple regression (OLS)
regress voteintent_afd int_pol_use1 i.bik i.bl, vce(cluster plz)
regress voteintent_afd int_pol_use1 `cntrls_de_individual' i.bik i.bl, vce(cluster plz)
regress voteintent_afd int_pol_use1 `cntrls_de', vce(cluster plz)

*** Multinomial logit
mlogit voteintent int_pol_use1, baseoutcome(4) vce(cluster plz)
margins, dydx(int_pol_use1) post
mlogit voteintent int_pol_use1 `cntrls_de_individual' i.bik i.bl, baseoutcome(4) vce(cluster plz)
margins, dydx(int_pol_use1 age10 sex *edu_cat3_rev employed) post
mlogit voteintent int_pol_use1 `cntrls_de', baseoutcome(4) vce(cluster plz)
margins, dydx(int_pol_use1 age10 sex *edu_cat3_rev employed popdens021 slope1 unempl01 over65_01 degrees_univ08) post

*** Reduced form
eststo rfnaive: regress voteintent_afd mbits61 i.bik i.bl, vce(cluster plz)
eststo rfind: 	regress voteintent_afd mbits61 `cntrls_de_individual' i.bik i.bl, vce(cluster plz)
eststo rffull: 	regress voteintent_afd mbits61 `cntrls_de', vce(cluster plz)

*** 2SLS
eststo tslsnaive:	ivregress 2sls voteintent_afd i.bik i.bl (int_pol_use1 = mbits61), vce(cluster plz) first
eststo tslsind:		ivregress 2sls voteintent_afd `cntrls_de_individual' i.bik i.bl (int_pol_use1 = mbits61), vce(cluster plz) first
eststo tslsfull:	ivregress 2sls voteintent_afd `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz) first
eststo tslsfirst:	regress int_pol_use1 mbits61 `cntrls_de', vce(cluster plz)
* Note: SE indistiguishable from ivregress results


* Reduced form results, all parties
esttab voteintrf_p6 voteintrf_p1 voteintrf_p2 voteintrf_p3 voteintrf_p4 voteintrf_p5, b(3) se(3) mtitles nonumbers r2 sfmt(%9.3fc) label ///
order(mbits61) star(* 0.1 ** 0.05 *** 0.001) scalars(F) drop(*bik10) indicate("Region fixed effects = *bl") 

* TSLS results, all parties
esttab voteint2sls_p6 voteint2sls_p1 voteint2sls_p2 voteint2sls_p3 voteint2sls_p4 voteint2sls_p5, b(3) se(3) mtitles nonumbers r2 sfmt(%9.3fc) label ///
order(int_pol_use1) star(* 0.1 ** 0.05 *** 0.001) scalars(F) drop(*bik10) indicate("Region fixed effects = *bl") 

* Table 1 First-stage results
esttab tslsfirst, b(3) se(3) mtitles nonumbers r2 sfmt(%9.3fc) label ///
order(mbits61) star(* 0.1 ** 0.05 *** 0.001) scalars(F) drop(*bik10) indicate("Region fixed effects = *bl") varwidth(27) 

* Table 4 IV results, plus naive results
esttab rfnaive rffull tslsnaive tslsfull, b(3) se(3) mtitles nonumbers r2 sfmt(%9.3fc) label ///
order(mbits61 int_pol_use1) star(* 0.1 ** 0.05 *** 0.001) scalars(F) drop(*bik10) indicate("Region fixed effects = *bl") varwidth(35)

* Table 3 Simple regression results
local cntrls_de_individual age10 sex i.edu_cat3_rev employed
local cntrls_de age10 sex i.edu_cat3_rev employed popdens021 slope1 unempl01 over65_01 degrees_univ08 i.bik i.bl 
eststo clear
quietly eststo olssimple:	regress voteintent_afd int_pol_use1 i.bik i.bl, vce(cluster plz)
quietly eststo olsfull: 	regress voteintent_afd int_pol_use1 `cntrls_de', vce(cluster plz)
tab voteintent
tab voteintent, nolab
quietly mlogit voteintent int_pol_use1 `cntrls_de' i.bik i.bl, baseoutcome(4) vce(cluster plz)
eststo vml
foreach o in 322 1 6 5 7{
quietly margins, dydx(int_pol_use1 age10 sex *edu_cat3_rev employed popdens021 slope1 unempl01 over65_01 degrees_univ08) predict(outcome(`o')) post
eststo, title(Outcome `o')
estimates restore vml
}
eststo drop vml
esttab, b(3) se(3) mtitles nonumbers r2 sfmt(%9.3fc) label star(* 0.1 ** 0.05 *** 0.001) scalars(F) drop(*bik10 *bl) varwidth(35)


*** IV estimate plot
coefplot ///
rffull, msize(medium) msymbol(S) mcolor(black) level(90 95) ///
ciopts(lwidth(*1.5) lcolor(black)) xlabel(-.3 (.1) .5) xscale(range(-.3 (.1) .55)) ///
keep(mbits61) ylab("") xline(0) title("Reduced form", size(large) position(11)) ///
name(plotrf, replace) fysize(50) legend(off) fxsize(50)
coefplot ///
tslsfull, msize(medium) msymbol(S) mcolor(black) level(90 95) ///
ciopts(lwidth(*1.5) lcolor(black)) xlabel(-.6 (.3) 1.2) xscale(range(-.6 (.2) 1.2)) ///
keep(int_pol_use1) ylab("") xline(0) title("2SLS", size(large) position(11)) ///
name(plot2sls, replace) fysize(50) legend(off) fxsize(50)
graph combine plotrf plot2sls, col(1) title("IV estimates Germany", size(large)) name(ivgermany, replace)
graph export iv_estimates_germany.pdf, name(ivgermany) replace



//// IV for all parties

tab voteintent, gen(voteintent_party)

*** Reduced form 
eststo voteintrf_p1: regress voteintent_party1 mbits61 `cntrls_de', vce(cluster plz)
eststo voteintrf_p2: regress voteintent_party2 mbits61 `cntrls_de', vce(cluster plz)
eststo voteintrf_p3: regress voteintent_party3 mbits61 `cntrls_de', vce(cluster plz)
eststo voteintrf_p4: regress voteintent_party4 mbits61 `cntrls_de', vce(cluster plz)
eststo voteintrf_p5: regress voteintent_party5 mbits61 `cntrls_de', vce(cluster plz)
eststo voteintrf_p6: regress voteintent_party6 mbits61 `cntrls_de', vce(cluster plz)
eststo voteintrf_p7: regress voteintent_party7 mbits61 `cntrls_de', vce(cluster plz)

* Plot
coefplot ///
(voteintrf_p6, label(AfD)) (voteintrf_p1, label(CDU)) (voteintrf_p2, label(SPD)) (voteintrf_p3, label(FDP)) ///
(voteintrf_p4, label(Greens)) (voteintrf_p5, label(Left)), ///
ciopts(lwidth(*1.5) lcolor(black)) level(90 95) xlabel(-.4 (.1) 0.5) xscale(range(-.45 (.2) 0.55)) ///
keep(mbits61) ylab("") xline(0) title("Reduced form estimates, all parties, Germany", size(large) position(11)) name(voteintrf_p, replace) 
graph export rf_all_parties_germany.pdf, name(voteintrf_p) replace

*** 2SLS
eststo voteint2sls_p1: ivregress 2sls voteintent_party1 `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)
eststo voteint2sls_p2: ivregress 2sls voteintent_party2 `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)
eststo voteint2sls_p3: ivregress 2sls voteintent_party3 `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)
eststo voteint2sls_p4: ivregress 2sls voteintent_party4 `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)
eststo voteint2sls_p5: ivregress 2sls voteintent_party5 `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)
eststo voteint2sls_p6: ivregress 2sls voteintent_party6 `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)
eststo voteint2sls_p7: ivregress 2sls voteintent_party7 `cntrls_de' (int_pol_use1 = mbits61), vce(cluster plz)

* Plot
coefplot ///
(voteint2sls_p6, label(AfD)) (voteint2sls_p1, label(CDU)) (voteint2sls_p2, label(SPD)) (voteint2sls_p3, label(FDP)) ///
(voteint2sls_p4, label(Greens)) (voteint2sls_p5, label(Left)), ///
ciopts(lwidth(*1.5) lcolor(black)) level(90 95) xlabel(-1.2 (.3) 1.2) xscale(range(-1.25 (.3) 1.25)) ///
keep(int_pol_use1) ylab("") xline(0) title("TSLS estimates, all parties, Germany", size(large) position(11)) name(voteint2sls_p, replace) 
graph export 2sls_all_parties_germany.pdf, name(voteint2sls_p) replace



//// Falsification test

*** First stage
regress int_pol_use1 mbits61 `cntrls_de', vce(cluster plz)
eststo fs_actual: margins, dydx(mbits61) post
regress newspaper_read mbits61 `cntrls_de', vce(cluster plz)
eststo fs_falsify: margins, dydx(mbits61) post

* Plot
coefplot ///
(fs_actual, label(Internet use)) (fs_falsify, label(Newspaper reading)), ///
ylab("") title("First-stage estimates Germany", size(large) position(11)) xline(0) fxsize(50) ///
legend(pos(6)) ciopts(lwidth(*1.5) lcolor(black)) level(90 95)  name(falsification_test_gemany, replace)
graph export falsification_test_gemany.pdf, name(falsification_test_gemany) replace



//// Relative size of predictors when including left-right scale, trust in parties and political interest

eststo relsize: regress voteintent_afd int_pol_use1 lrscale1 polint1 `cntrls_de', vce(cluster plz) 

* Plot
coefplot relsize, ///
ciopts(lwidth(*1.5) lcolor(black)) level(90 95) xlabel(-.2 (.1) .6) xscale(range(-.2 (.1) .6)) ///
keep(age10 sex *edu_cat3_rev int_pol_use1 lrscale1 polint1) xline(0) /// 
title("Predictors of populist vote Germany", position(11) size(large)) name(relsize, replace)
graph export predictors_germany.pdf, name(relsize) replace


//// Orthogonality
eststo ortho: regress mbits61 age10 sex i.job_en_ex i.class_cat3 i.edu_cat3_rev lrscale1 polint1 popdens021 slope1 unempl01 over65_01 degrees_univ08 i.bik i.bl, cluster(plz) 

* Plot
coefplot ortho, ///
drop(_cons popdens021 slope1 unempl01 over65_01 degrees_univ08 *bik10 *bl) ///
ciopts(lwidth(*1.5) lcolor(black)) level(90 95) xlabel(-.02 (.01) .025) xscale(range(-.02 (.01) .025)) ///
xline(0) title("DV: Broadband coverage Germany", size(large) pos(11)) aspectratio(1) name(orthogonality, replace)
graph export orthogonality_germany.pdf, name(orthogonality) replace



//// Heterogeneous effects 

local cntrls_de age10 sex i.edu_cat3_rev employed popdens021 slope1 unempl01 over65_01 degrees_univ08 i.bik i.bl 

* Mech: Left-right
tab lr3cat
tab lr3cat, nolab
quietly regress voteintent_afd c.mbits61##lr3cat `cntrls_de', vce(cluster plz)
margins, at(lr3cat=(1 2 3) mbits61=(.26 1)) post coefl
eststo hetlrcat: nlcom (_b[4._at]-_b[1bn._at]) (_b[5._at]-_b[2._at]) (_b[6._at]-_b[3._at]), post

coefplot ///
hetlrcat, rename(_nl_1 = "Left" _nl_2 = "Center" _nl_3 = "Right") ///
level(90 95) ciopts(lwidth(*1.5) lcolor(black)) xlabel(-.6 (.2) .65) xscale(range(-.6 (.25) .65)) ///
xline(0) title("Left-right scale", size(large) position(11)) ///
name(hetleftright, replace) fysize(55) legend(off) fxsize(50)

* Mech: Class
tab class_cat3
tab class_cat3, nolab
quietly regress voteintent_afd c.mbits61##class_cat3 `cntrls_de', vce(cluster plz)
margins, at(class_cat3=(1 2 3) mbits61=(.26 1)) post coefl
eststo hetclass: nlcom (_b[4._at]-_b[1bn._at]) (_b[5._at]-_b[2._at]) (_b[6._at]-_b[3._at]), post

coefplot ///
hetclass, rename(_nl_1 = "Lower" _nl_2 = "Middle" _nl_3 = "Upper-middle") ///
level(90 95) ciopts(lwidth(*1.5) lcolor(black)) xlabel(-.4 (.2) .7) xscale(range(-.4 (.25) .7)) ///
xline(0) title("Social class", size(large) position(11)) ///
name(hetclass, replace) fysize(55) legend(off) fxsize(50)

* Mech: Turnout 2013
tab voted2013
tab voted2013, nolab
quietly regress voteintent_afd c.mbits61##i.voted2013 `cntrls_de', vce(cluster plz)
margins, at(voted2013=(0 1) mbits61=(.26 1)) post coefl
eststo hetturnout2013: nlcom (_b[3._at]-_b[1bn._at]) (_b[4._at]-_b[2._at]), post

coefplot ///
hetturnout2013, rename(_nl_1 = "Did not vote" _nl_2 = "Voted 2013"  ) ///
level(90 95) ciopts(lwidth(*1.5) lcolor(black)) xlabel(-1.5 (.5) 1) xscale(range(-1.5 1)) ///
xline(0) title("Turnout 2013", size(large) position(11)) ///
name(hetturnout2013, replace) fysize(45) legend(off) fxsize(50)

* Mech: Age
tab age_cat3
tab age_cat3, nolab
quietly regress voteintent_afd c.mbits61##i.age_cat3 sex i.edu_cat3_rev employstat popdens021 slope1 unempl01 over65_01 degrees_univ08 i.bik i.bl , vce(cluster plz)
margins, at(age_cat3=(0 1 2) mbits61=(.26 1)) post coefl
eststo hetage: nlcom (_b[4._at]-_b[1bn._at]) (_b[5._at]-_b[2._at]) (_b[6._at]-_b[3._at]), post

coefplot ///
hetage, rename(_nl_1 = "18-29" _nl_2 = "30-60" _nl_3 = "60+") ///
level(90 95) ciopts(lwidth(*1.5) lcolor(black)) xlabel(-.4 (.2) .7) xscale(range(-.4 (.25) .7)) ///
xline(0) title("Age", size(large) position(11)) ///
name(hetage, replace) fysize(55) legend(off) fxsize(50)


 
